package com.bankfourfactor.nanyun;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bankfourfactor.APPBankCarFactor;
import com.bankfourfactor.BankCarFactorEntity;
import com.bankfourfactor.BankCarFactoryConstant;
import com.ny.lib.NySignatureData;
import com.ny.lib.NySignatureStrUtil;

import net.sf.json.JSONObject;

public class NanYunFourFactor {
	
	private static Logger logger = LoggerFactory.getLogger(NanYunFourFactor.class);
	
	
	public static Map<String,Object> submitNanYunFactor(BankCarFactorEntity b) throws Exception{
		Map<String,String> data = new HashMap<String,String>();
		data.put("version", BankCarFactoryConstant.NANYUN_VERSION);
		data.put("merId", BankCarFactoryConstant.NANYUN_MERID);
		//todo 使用dateutil，减少原生SimpleDateFormat使用
		data.put("transDate",  new SimpleDateFormat("yyyyMMdd").format(new Date()));//交易日期(yyyyMMdd)
		data.put("transType","10");	
		data.put("seqId",  System.currentTimeMillis()+""+b.getCustId());//流水号
		data.put("transTime", new SimpleDateFormat("HHmmss").format(new Date()));
		data.put("cardNo",b.getCardNo());						
		data.put("name",b.getCardName());
		data.put("certNo",b.getIdNo());
		data.put("phone",b.getPhone());
		NySignatureData signatureData = new NySignatureData();
		String info=NySignatureStrUtil.getBankSignatureString(data,NyBase.encoding);
		String signature = signatureData.sign(info, BankCarFactoryConstant.NANYUN_PRIVATE_KEY);
		data.put("sign", signature);
		logger.info("楠云科技-----请求报文=["+data.toString()+"]");
		Map resmap = NyBase.submitUrl(data,BankCarFactoryConstant.NANYUN_URL);
		logger.info("楠云科技-----应答报文=["+resmap.toString()+"]");
		return resmap;
	}
	
	
}
